﻿function loadData(recordID) {
    recordid = recordID;
    if ($("#hidden1") != null) {
        $("#hidden1").val('0');
    }
    PageMethods.loadECGRecord(recordID, OnSuccessLoadData);
    document.getElementById("lbRecordID").innerHTML = recordID;
}

function loadData12(recordID) {
    //bật ảnh load dữ liệu
    $(".canvasDiv4Doctor").hide(); // Đối với trang bác sĩ - hide div vẽ canvas
    $(".canvas_div").hide(); //Đối với trang bệnh nhân - hide div vẽ canvas
    $(".loadingimage_div").show();

    recordid = recordID;
    if ($("#hidden1") != null) {
        $("#hidden1").val('0');
    }
    PageMethods.loadECGRecord12(recordID, OnSuccessLoadData12);
    document.getElementById("lbRecordID").innerHTML = recordID;
}

function onFailed(error) {
    alert(error);
}

function OnSuccessLoadData12(response) {
    //sau khi load dữ liệu thì bỏ ảnh loading
    $(".loadingimage_div").hide();
    $(".canvasDiv4Doctor").show();
    $(".canvas_div").show();   

    var resultArr = response.split('\t');    
    arr = resultArr.splice(0, 12);
        
    dataArr = resultArr;

    if (arr[0] == 1) {        
        drawGraph12(resultArr, 'canvasI', 70, 1);
    }
    if (arr[1] == 1) {
        drawGraph12(resultArr, 'canvasII', 70, 2);
    }
    if (arr[2] == 1) {
        drawGraph12(resultArr, "canvasIII", 70, 3);
    }
    if (arr[3] == 1) {
        drawGraph12(resultArr, "canvasaVR", 70, 4);
    }
    if (arr[4] == 1) {
        drawGraph12(resultArr, "canvasaVL", 70, 5);
    }
    if (arr[5] == 1) {
        drawGraph12(resultArr, "canvasaVF", 70, 6);
    }
    if (arr[6] == 1) {
        drawGraph12(resultArr, "canvasV1", 70, 7);
    }
    if (arr[7] == 1) {
        drawGraph12(resultArr, "canvasV2", 70, 8);
    }
    if (arr[8] == 1) {
        drawGraph12(resultArr, "canvasV3", 70, 9);
    }
    if (arr[9] == 1) {
        drawGraph12(resultArr, "canvasV4", 70, 10);
    }
    if (arr[10] == 1) {
        drawGraph12(resultArr, "canvasV5", 70, 11);
    }
    if (arr[11] == 1) {
        drawGraph12(resultArr, "canvasV6", 70, 12);
    }

    length = resultArr.length;
    leadLength = Math.round(length / 13);
    //Đối với bản ghi thời gian dạng số
    //var maxX = Math.round(resultArr[13 * (leadLength - 1)] / 10);

    //Đối với bản ghi dạng hh:mm:ss:mmm
    var maxX = Math.round(resultArr[13 * (leadLength - 1)].split(':')[1] * 100);
    document.getElementById("scrollBar").width = maxX;
}

function OnSuccessLoadData(response) {
    var result = response;
    var arr = result.split(",");    

    var x = new Array();
    var y = new Array();
    // arr.length phai tru 1 vi trong xau ki tu cuoi cung la ',' nen arr ki tu cuoi cung la null do dung ham split 
    length = (arr.length - 1) / 2;
    for (i = 0; i < length; i += 1) {
        x[i] = arr[2 * i];
        y[i] = arr[2 * i + 1];
    }

    xArr = x;
    yArr = y;

    drawGraph(x, y, 'canvasI', 70);
    drawGraph(x, y, 'canvasII', 70);
    drawGraph(x, y, 'canvasIII', 70);
    drawGraph(x, y, 'canvasaVR', 70);
    drawGraph(x, y, 'canvasaVL', 70);
    drawGraph(x, y, 'canvasaVF', 70);
    drawGraph(x, y, 'canvasV1', 70);
    drawGraph(x, y, 'canvasV2', 70);
    drawGraph(x, y, 'canvasV3', 70);
    drawGraph(x, y, 'canvasV4', 70);
    drawGraph(x, y, 'canvasV5', 70);
    drawGraph(x, y, 'canvasV6', 70);

    //Ve scrollbar - thuc chat la keo dan the div co id la scrollBar
    length = x.length;
    var maxX = x[length - 1];
    document.getElementById("scrollBar").width = maxX;
}